﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Creative85.Framework.Data;
using Project32CHE.Biz.Goods.Extend.Model;

namespace Project32CHE.Biz.Goods.Extend.Providers
{
    class GoodsAddProvider : AbstractProvider
    {
        public override string Type
        {
            get { return "新建商品"; }
        }

        protected override InventorySheet ProcessCore(params object[] parameters)
        {
            var storageId = (Guid)parameters[0];
            var goodsId = this.Id;
            var quantity = (decimal)parameters[1];
            var goods = Db.Instance.SingleById<Goods.Model.Goods>(goodsId);
            var part = new InventoryPart()
            {
                CostPrice = goods.CostPrice,
                GoodsId = goods.ID,
                Operator = InventoryOperate.StoreIn,
                Quantity = quantity,
                SalePrice = goods.SalePrice,
                SortId = 0,
                StorageId = storageId
            };
            var parts = new List<InventoryPart>() { part };
            parts = parts.Where(x => x.Quantity > 0).ToList();
            var result = new InventorySheet()
            {
                Id = goodsId,
                Code = goods.GoodsCode,
                DateTime = goods.CreateTime,
                IsChangeCostPrice = false,
                Parts = parts,
                ShopId = goods.ShopID,
                UnionId = goods.UnionID,
                StorageId = storageId,
                OperatorId = Guid.Empty,
                OperatorName = goods.OperatorName
            };
            return result;
        }

        protected override InventorySheet UnProcessCore(params object[] parameters)
        {
            throw new NotImplementedException();
        }
    }
}
